package cn.tedu.csmall.product.controller;

import cn.tedu.csmall.product.pojo.dto.PictureAddNewDTO;
import cn.tedu.csmall.product.service.IPictureService;
import cn.tedu.csmall.product.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.validator.constraints.Range;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@Api(tags = "06. 图片管理模块")
@RestController
@RequestMapping("/pictures")
public class PictureController {

    @Autowired
    IPictureService pictureService;

    @ApiOperation("添加图片")
    @ApiOperationSupport(order = 100)
    @PostMapping("/add-new")
    public JsonResult addNew(PictureAddNewDTO pictureAddNewDTO){
        log.debug("开始处理【添加图片】请求，新图片：{}", pictureAddNewDTO);
        pictureService.addNew(pictureAddNewDTO);
        return JsonResult.ok();
    }

    @ApiOperation("删除图片")
    @ApiOperationSupport(order = 200)
    @ApiImplicitParam(name = "id", value = "图片id", required = true, dataType = "long")
    @PostMapping("/{id:[0-9]+}/delete")
    public JsonResult delete(@PathVariable Long id) {
        log.debug("开始处理【删除相册】的请求，参数：{}", id);
        pictureService.delete(id);
        return JsonResult.ok();
    }
}
